import send_msg from '@feidao-factory/send-msg';

/**
 * 调用nodejs服务
 * @param action_id 系统参数actionid
 * @param session_id 系统参数sessionid
 * @param spaceid 项目spaceid
 * @param service_name 服务名称
 * @param condition 服务参数，参数key不能包含：spaceid, modelid
 * @example nodejs(action_id, session_id, spaceid, service_name);
 */
export default function nodejs<T>(action_id: string, session_id: string, spaceid: string, service_name: string, condition = {}) {
	const params = {
		...condition,
		modelid: 'custom::js_' + service_name,
		spaceid
	};
	// return send_msg<T>(action_id, session_id, 'dataservice.nodejs', params);
	return send_msg<T>(action_id, session_id, 'dataservice.nodejs', params)
		.catch((e) => {
			console.error(`--调用服务${service_name}失败--错误信息---`, e ? e.toString() : '');
			// const err = e ? e.toString() : '';
			return Promise.reject(e.message);
		}) as Promise<T>;
}
